<template>
  <div class="house-item">
    <div class="item-inner">
      <div class="cover" v-if="itemData.image">
        <img :src="itemData.image.url" alt="" />
      </div>
      <div class="info">
        <div class="location">
          <van-icon name="location" />{{ itemData.location }}
        </div>
        <div class="houseName">
          {{ itemData.houseName }}
        </div>
        <div class="summaryText">{{ itemData.summaryText }}</div>
        <div class="price">
          <span class="finalPrice">{{ itemData.finalPrice }}</span>
          <span class="productPrice">￥{{ itemData.productPrice }}</span>
          <span class="discounts"
            ><van-icon name="fire-o" /> 已减{{ discounts }}</span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from "@vue/runtime-core";

const data = defineProps({
  itemData: {
    type: Object,
    default: () => ({}),
  },
});
const discounts = computed(() => {
  return data.itemData.productPrice - data.itemData.finalPrice;
});
</script>

<style lang="less" scoped>
.house-item {
  position: relative;
  width: 48%;
  margin: 4px 0;
  border-radius: 10px;
  overflow: hidden;
  .cover {
    position: relative;
    img {
      width: 100%;
    }
  }
  .info {
    padding: 10px;
    .location {
      font-size: 14px;
      color: #666666;
    }
    .houseName {
      width: 100%;
      font-size: 14px;
      word-break: break-all;
      text-overflow: ellipsis;
      overflow: hidden;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2; /* 这里是超出几行省略 */
      margin: 4px 0;
    }
    .summaryText {
      font-size: 12px;
      color: #666666;
      margin: 4px 0;
    }
    .price {
      .finalPrice {
        font-size: 16px;
        color: var(--color);
      }
      .productPrice {
        font-size: 12px;
        text-decoration: line-through;
        margin: 0 2px;
      }
      .discounts {
        color: #fff;
        background-image: linear-gradient(var(--color), #fcae3e);
        padding: 0 4px;
        border-radius: 10px;
      }
    }
  }
}
</style>
